package managedbean.FRM.SupplierPayment;

import entity.SCM.Supplier;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.PhaseEvent;
import session.stateless.SCM.SupplierBeanLocal;

@ManagedBean(name="viewSupplierPaymentsManagerBean")
@ViewScoped
public class ViewSupplierPaymentsManagerBean implements Serializable {
    public ViewSupplierPaymentsManagerBean() {}

    @EJB
    private SupplierBeanLocal supplierBeanLocal;
    
    private Supplier selectedSupplier;
    private String statusMessage;
    private boolean isExisting;
    private String saleLeadName;
    
    public void initView(PhaseEvent event){
        try
        {
            if(selectedSupplier!=null)
                this.setIsExisting(true);
            else this.setIsExisting(false);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();            
        }
    }

    public boolean isIsExisting() {
        return isExisting;
    }

    public void setIsExisting(boolean isExisting) {
        if (selectedSupplier!= null)
            this.isExisting=true;
        else this.isExisting=false;
        
    }

    public String getSaleLeadName() {
        return saleLeadName;
    }

    public void setSaleLeadName(String saleLeadName) {
        this.saleLeadName = saleLeadName;
    }

    public String getStatusMessage() {
        return statusMessage;
    }

    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }

    public Supplier getSelectedSupplier() {
        return selectedSupplier;
    }

    public void setSelectedSupplier(Supplier selectedSupplier) {
        this.selectedSupplier = selectedSupplier;
    }
    
    public void retrieve()
    {
        if (saleLeadName!=null)
        {
            this.setSelectedSupplier(supplierBeanLocal.findSupplierByName(saleLeadName));
        }
    }
    
    public List<String> complete(String query) {  
        List<String> results = new ArrayList<String>();  
        
        List<Supplier> list = supplierBeanLocal.getAllSupplier();
        
        for (int i = 0; i < list.size(); ++i)
        {
            if (list.get(i).getSupplierName().toLowerCase().contains(query.toLowerCase()))
                results.add(list.get(i).getSupplierName());
        }
        
        return results;  
    }
        
}
